package com.masterclient.app.businessmodule.minemodule.message.detail;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eoner.baselib.fragment.FCBaseFragment;
import com.eoner.baselib.widget.navgation.FCNavigationBar;
import com.eoner.baselibrary.bean.personal.GivingListBean;
import com.masterclient.app.R;
import com.masterclient.app.businessmodule.minemodule.contract.ActivityListContract;
import com.masterclient.app.businessmodule.minemodule.contract.ActivityListPresenter;
import com.masterclient.app.businessmodule.minemodule.message.adapter.GivingMsgAdapter;
import com.masterclient.app.modules.bridge.BridgeActivity;

import butterknife.BindView;

public class GivingMsgFragment extends FCBaseFragment<ActivityListPresenter> implements ActivityListContract.View  {

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.swipeLayout)
    SwipeRefreshLayout swipeLayout;

    private GivingMsgAdapter givingMsgAdapter;
    private View emptyView;
    private boolean isMore;

    @Override
    protected int requireGetLayoutId() {
        return R.layout.fragment_notice_list;
    }

    @Override
    protected void requireSetCustomNavigationBar(FCNavigationBar navigationBar) {
        navigationBar.setVisibility(View.GONE);
    }

    @Override
    protected void requireInitUIAndData(Bundle savedInstanceState) {
        isMore = false;
        emptyView = View.inflate(getContext(),R.layout.null_order,null);
        emptyView.setVisibility(View.GONE);
        ((TextView) emptyView.findViewById(R.id.tv_tip)).setText("暂时没有活动推荐哦");

        givingMsgAdapter = new GivingMsgAdapter();
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.setAdapter(givingMsgAdapter);
        givingMsgAdapter.bindToRecyclerView(recyclerView);
        mPresenter.getZsqNoticeList();

        givingMsgAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                GivingListBean.GivingItemBean itemBean = mPresenter.lists.get(position);
                startActivitryWithBundle(BridgeActivity.class, new String[][]{{"url", itemBean.getSkip_url()}});
            }
        });

        swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mPresenter.getZsqNoticeList();
            }
        });
    }


    @Override
    public void showZsqListData(GivingListBean givingListBean) {
        if (swipeLayout.isRefreshing()) {
            swipeLayout.setRefreshing(false);
        }
        mPresenter.lists.clear();
        if (givingListBean.getData() != null && givingListBean.getData().getList()!=null && givingListBean.getData().getList().size() > 0) {
            emptyView.setVisibility(View.GONE);
            mPresenter.lists = givingListBean.getData().getList();
        } else {
            emptyView.setVisibility(View.VISIBLE);
        }
        givingMsgAdapter.setNewData(mPresenter.lists);
        givingMsgAdapter.notifyDataSetChanged();
    }

    @Override
    public void showZsqFailed() {
        if (swipeLayout.isRefreshing()) {
            swipeLayout.setRefreshing(false);
        }
//        if (mPresenter.lists == null||mPresenter.lists.size()<=0){
//            emptyView.setVisibility(View.VISIBLE);
//        }
    }


}
